package com.erp.controller.sales;


import com.erp.common.annotation.Anonymous;
import com.erp.common.core.controller.BaseController;
import com.erp.common.core.domain.AjaxResult;
import com.erp.common.core.page.TableDataInfo;
import com.erp.domain.ErpCustomer;
import com.erp.domain.ErpSalesOutbound;
import com.erp.domain.ErpSalesProduct;
import com.erp.service.sales.IErpSalesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author cuicui
 * @Description
 * @Date 2025-9-1
 */
@RestController
@RequestMapping("/erp/sales")
public class ErpSalesController extends BaseController {
    @Autowired
    private IErpSalesService erpSalesService;

    /**
     * 查询销售单列表
     */
    // 该注解表示访问路径为"/erp/sales/list"
    @GetMapping("/list")
    // 该注解表示该路径可以匿名访问
    @Anonymous
    public TableDataInfo list(ErpSalesOutbound erpSalesOutbound) {
        startPage();
        List<ErpSalesOutbound> list = erpSalesService.selectErpSalesList(erpSalesOutbound);
        return getDataTable(list);
    }

    /**
     * 查询客户
     */
    @GetMapping("/customer/list")
    @Anonymous
    public List<ErpCustomer> customer(@RequestParam("customerId") String customerId) {
        return erpSalesService.selectErpCustomerById(customerId);
    }

    /**
     * 查询商品
     */
    @GetMapping("/product/list")
    @Anonymous
    public List<ErpSalesProduct> product(@RequestParam("soNo") String soNo) {
        return erpSalesService.selectErpProductById(soNo);
    }

    /**
     * 获取出库图表数据
     */
    @GetMapping("/getSalesCharts")
    public AjaxResult getSalesData() {
        // 根据性别查询数量
        List<String> countSoNo = erpSalesService.countBySoNo();
        List<Double> countAllAmount = erpSalesService.countByAllAmount();

        HashMap<String, List<Object>> map = new HashMap<>();
        map.put("soNolist", Arrays.asList("出库单号", "总金额"));
        map.put("AllAmountList", Arrays.asList(countSoNo, countAllAmount));
        return AjaxResult.success(map);
    }
}
